<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>创建合同订单</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
    <script src="${ctxStatic}/js/DateTimePicker.js"></script>
    <script src="${ctxStatic}/js/layer.js"></script>
    <script src="${ctxStatic}/js/style.js"></script>
    <script src="${ctxStatic}/dateCalendar/WdatePicker.js"></script>
    <link rel="stylesheet" href="${ctxStatic}/css/common.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <script type="text/javascript">
    $(document).ready(function(){
    	var form = $("#inputForm");  
        form.validate();//验证指定的表单
    	$("#rackID").select2();
    	$("#warehouseID").select2();
   		$("#saveButton").click(function(){
    		if (form.valid()) {//如果表单验证成功，则进行提交。  
    			var requestQuantity = "${materialOutInbound.requestQuantity }".replace(/,/g,"");
    			var realQuantity = "${materialOutInbound.realQuantity}".replace(/,/g,"");
    			var residueQuantity = parseFloat(requestQuantity)-parseFloat(realQuantity);
    			var inventoryQuantity = $("#inventoryQuantity").val();
    			inventoryQuantity = parseFloat(inventoryQuantity.replace(/,/g,""));
    			var strText = "";
    			if (inventoryQuantity>residueQuantity) {
    				strText = "<spring:message code="inventory_detail_tips_msg_residueQuantity"/>"+residueQuantity+"\n<spring:message code="inventory_detail_tips_msg_areyousure"/>";
    				if (confirm(strText)) {
	            		return saveForm();
					}
				}else{
					return saveForm();
				}
          	}
     	});
    });
    
    /* 保存创建/编辑信息 */
    function saveForm(){
    	var inventoryQuantity = $("#inventoryQuantity").val();
    	inventoryQuantity = inventoryQuantity.replace(/,/g,"");
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/material/inbound/saveDetail?inventoryQuantity="+inventoryQuantity,params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		
    		window.parent.frames[2].materialDetailList();
    		closeWin();
    	},'json');
    	
    }
    
    function warehouseList() {
    	var warehouseID = $("#warehouseID").find("option:selected").val();;
    	param={"warehouseID":warehouseID};
    	$.post("${ctx}/material/inbound/findRack",param,function(result){            
        	$("#rackHtml").html($(callBackHtml(result)).find("#rackHtml").html());
        	$("#rackID").select2();
        },'html');
	}
    
    </script>
    <style type="text/css">
	.showHtml input{
	border:none;
	background-color:inherit;
	color:#333;
	}
    </style>
</head>
<form id="inputForm">
<body>   
<div  class="layerHeader clearfix">	      
             <p class="headerTitle"><spring:message code="inventory_detail_set_warehouseRack"/></p>    
    <div class="headerButton clearfix">
			<button type="button" id="saveButton"><spring:message code="common_save" /></button>
        <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="purchaseAdvance_edit_cancle"/></button>
    </div>
</div>

<div id="showHtml" class="smOrderBox">
<input type="hidden" name="id" value="${materialOutInbound.id }"/>
<input type="hidden" name="inventoryDetailId" value="${materialOutInbound.inventoryDetailId }"/>
<input type="hidden" name="materialId" value="${materialOutInbound.materialId }"/>
<input type="hidden" name="inventoryInOutKbn" value="${materialOutInbound.inventoryInOutKbn }"/>
<input type="hidden" name="inventoryCategory" value="${materialOutInbound.inventoryCategory }"/>
    <div class="items clearfix showHtml">
        <div class="col-50 clearfix">
        <!-- 物料编号 -->
            <p class="tit"><spring:message code="inventory_detail_set_materialCode"/></p>
            <p>${materialOutInbound.materialCode }</p>
        </div>
        <div class="col-50 clearfix ">
        <!-- 物料名称  -->
            <p class="tit"><spring:message code="inventory_detail_set_materialName"/></p>
            <p>${materialOutInbound.materialNameCn }</p>
        </div>
        
    </div>
    <div class="items clearfix">
        <div class="col-50 clearfix">
        <!-- 申请数量  -->
            <p class="tit"><spring:message code="inventory_detail_set_requestQuantity"/></p>
            <p>${materialOutInbound.requestQuantity }</p>
        </div>
        <div class="col-50 clearfix haveToBox">
        <!-- 入库数量  -->
            <p class="tit"><spring:message code="inventory_detail_set_inventoryQuantity"/></p>
             <input type="text" style="width: 120px;" id="inventoryQuantity" value="<fmt:formatNumber value="" pattern="#,##0.###"/>" onblur="formatNumber(this);" onfocus="unFormat(this);" data-rule-required="true"  data-msg-required="<spring:message code="inventory_detail_error_msg_inventoryQuantity"/>">
             <p class="haveTo">*</p>
        </div>
    </div>
    <div class="items clearfix haveToBox" >        	
                
                <div class="col-50 clearfix">
                <!-- 仓库名称  -->
                    <p class="tit"><spring:message code="inventory_detail_set_warehouseName"/></p>
                    <select id="warehouseID" name="warehouseID" onchange="warehouseList();" style="width: 150px;" data-rule-required="true"  data-msg-required="<spring:message code="inventory_detail_error_msg_warehouseName"/>">
                    	<option value=""><spring:message code="customer_pleaseChoose"/></option>
                    	<c:forEach items="${materialOutInbound.warehouseList }" var="warehouse">
                    		<option value="${warehouse.warehouseID }">${warehouse.warehouseName }</option>
                    	</c:forEach>
                    </select>
                    <p class="haveTo">*</p>
                </div>
            </div>
    
            <div id="rackHtml" class="items clearfix haveToBox">        	
                <div class="col-50 clearfix">
                <!-- 货架位置  -->
                    <p class="tit"><spring:message code="inventory_detail_set_rackPlace"/></p>
                    <select id="rackID" name="rackID" style="width: 150px;" data-rule-required="true"  data-msg-required="<spring:message code="inventory_detail_error_msg_rackPlace"/>">
                    	<option value=""><spring:message code="customer_pleaseChoose"/></option>
                    	<c:forEach items="${materialOutInbound.rackList }" var="rack">
                    		<option value="${rack.rackID }">${rack.rackPlace }</option>
                    	</c:forEach>
                    </select>
           			<p class="haveTo">*</p>
                </div>
                
            </div>
</div>
</body>
</form>

<script>
	window.onload = function(){
	$('.tableScrollSm').css('height','325px')
	$('td input').each(function(){
		var tdH = $(this).parents('td').height()
		$(this).css('height',tdH)
		})
	}
	var tableW = $('.tableHead').outerWidth();
	$('.tableScroll').css('width',tableW + 18 + 'px')

</script>
</html>
